<html>
<head><meta charset="utf-8"><title>Valid example to use read_unaligned · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid.20example.20to.20use.20read_unaligned.html">Valid example to use read_unaligned</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169626986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid%20example%20to%20use%20read_unaligned/near/169626986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid.20example.20to.20use.20read_unaligned.html#169626986">(Jul 04 2019 at 07:38)</a>:</h4>
<p>Wanted: A valid usage example for <code>read_unaligned</code>. The one we currently have creates intermediate unaligned references.<br>
See <a href="https://github.com/rust-lang/rust/issues/62357" target="_blank" title="https://github.com/rust-lang/rust/issues/62357">https://github.com/rust-lang/rust/issues/62357</a>.</p>



<a name="169662413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid%20example%20to%20use%20read_unaligned/near/169662413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid.20example.20to.20use.20read_unaligned.html#169662413">(Jul 04 2019 at 17:33)</a>:</h4>
<p>This looks valid to me, unless something subtle is going on: <a href="https://github.com/Frommi/miniz_oxide/blob/b8e17c50a5068931257e1daac61c892e44693091/miniz_oxide/src/deflate/core.rs#L319" target="_blank" title="https://github.com/Frommi/miniz_oxide/blob/b8e17c50a5068931257e1daac61c892e44693091/miniz_oxide/src/deflate/core.rs#L319">https://github.com/Frommi/miniz_oxide/blob/b8e17c50a5068931257e1daac61c892e44693091/miniz_oxide/src/deflate/core.rs#L319</a><br>
It can be written completely safely with the same performance starting at Rust 1.34 though</p>



<a name="169672288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid%20example%20to%20use%20read_unaligned/near/169672288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Valid.20example.20to.20use.20read_unaligned.html#169672288">(Jul 04 2019 at 21:43)</a>:</h4>
<p>ah, good point! one can use it in slices</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>